﻿

using UtilPublic.Config;

namespace ServerBase.Config;

/// <summary>
/// 配置类公用接口
/// </summary>
public interface IConfigBase
{
    object GetKey();
}

/// <summary>
/// 配置文件
/// </summary>
public static partial class Conf
{
    /// <summary>
    /// 配置文件目录
    /// </summary>
    public static string ConfPathJson = $"../config/config/json/";

    public static string ConfListSeparator = UtilEnum.分隔符竖线;
    public static string ConfDictionarySeparator1 = UtilEnum.分隔符竖线;
    public static string ConfDictionarySeparator2 = UtilEnum.分隔符下划线;

    /// <summary>
    /// 初始化配置
    /// </summary>
    /// <returns></returns>
    public static bool InitConf()
    {
        bool result = true;

        var StopwatchProcess = Stopwatch.StartNew();
        result = InitConfSettings();
        StopwatchProcess.Stop();
        loger.Info($"InitConfSettings {StopwatchProcess.Elapsed}");

        if (result)
        {
            loger.Info("读取策划配置文件成功");
        }
        else
        {
            loger.Fatal("读取策划配置文件失败");
            return result;
        }

        return result;
    }

    /// <summary>
    /// 读取Dictionary配置
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <param name="Name"></param>
    /// <param name="confDic"></param>
    /// <returns></returns>
    public static bool ReadConfig<T1, T2>(string Name, ref Dictionary<T1, T2> confDic) where T1 : notnull
    {
        return ConfRead.ReadJsonDict(Name, ref confDic, ConfPathJson);
    }

}
